package com.example.lxj.archives.controller;

import java.util.List;
import java.util.Optional;

import com.example.lxj.archives.entity.TbCase;
import com.example.lxj.base.annoation.Permission;
import com.example.lxj.base.controller.BaseController;
import com.example.lxj.base.entity.AjaxRes;
import com.example.lxj.base.entity.PageDTO;
import com.example.lxj.base.entity.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.lxj.archives.service.ITbCaseService;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 案件Controller
 *
 * @author lxj
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/archives/case")
public class TbCaseController extends BaseController {
    @Autowired
    private ITbCaseService tbCaseService;

    /**
     * 查询案件列表
     */
    @Permission(value = "archives:case:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCase tbCase, PageDTO pageDTO) {
        startPage(Optional.ofNullable(pageDTO.getPageNo()).orElse(1), Optional.ofNullable(pageDTO.getPageSize()).orElse(10));
        List<TbCase> list = tbCaseService.selectTbCaseList(tbCase);
        return getDataTable(list);
    }

    /**
     * 获取案件详细信息
     */
    @Permission(value = "archives:case:query")
    @GetMapping(value = "/{caseId}")
    public AjaxRes getInfo(@PathVariable("caseId") Long caseId) {
        return success(tbCaseService.selectTbCaseByCaseId(caseId));
    }

    /**
     * 新增案件
     */
    @Permission(value = "archives:case:add")
    @PostMapping
    public AjaxRes add(@RequestBody TbCase tbCase) {
        return toAjax(tbCaseService.insertTbCase(tbCase));
    }

    /**
     * 修改案件
     */
    @Permission(value = "archives:case:edit")
    @PutMapping
    public AjaxRes edit(@RequestBody TbCase tbCase) {
        return toAjax(tbCaseService.updateTbCase(tbCase));
    }

    /**
     * 删除案件
     */
    @Permission(value = "archives:case:remove")
    @DeleteMapping("/{caseId}")
    public AjaxRes remove(@PathVariable("caseId") Long caseId) {
        return toAjax(tbCaseService.deleteTbCaseByCaseId(caseId));
    }
}
